
// Promise.resolve( value ) 返回一个 已兑现 的 Promise 实例


const value = [ 1 , 3 , 5 , 7 ];

/*
let executor = ( resolve , reject ) => {
    // 通过调用 resolve 函数来兑现承诺
    resolve( value );
}
let promise = new Promise( executor );
*/

// Promise.resolve( value )
// 返回一个 以给定值 解析后的 Promise 实例
let promise = Promise.resolve( value );
console.log( promise );

promise.then( params => {
    console.log( params );
});

console.log( '- '.repeat(10) );

const p1 = new Promise( ( resolve , reject ) => {
    setTimeout( function(){
        let rand = ( Math.random() * 1000 ) | 0 ;
        console.log( 'rand: ' , rand );
        // 通过调用 resolve 函数来兑现承诺
        resolve( rand );
    } , 1000 );
});

// 如果 Promise.resolve( value ) 的参数是个 Promise 则返回该 Promise
const p2 = Promise.resolve( p1 );

console.log( p1 === p2 );

p2.then( param => console.log( param ) , reason => console.log( reason ));
